package com.example.administrator.szb.activity;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.InputFilter;
import android.text.InputType;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.bigkoo.pickerview.TimePickerView;
import com.bigkoo.pickerview.listener.CustomListener;
import com.example.administrator.szb.R;
import com.example.administrator.szb.activity.base.BaseActivity;
import com.example.administrator.szb.adapter.BaseAdapter;
import com.example.administrator.szb.bean.SQYWBean;
import com.example.administrator.szb.bean.YWBDNEWBean;
import com.example.administrator.szb.tinkerutil.SampleApplicationLike;
import com.example.administrator.szb.http.HttpUtil;
import com.example.administrator.szb.http.URLAddress;
import com.example.administrator.szb.util.DialogUtil;
import com.example.administrator.szb.util.GetJsonDataUtil;
import com.example.administrator.szb.util.SPUtils;
import com.example.administrator.szb.util.ScreenExpressionUtils;
import com.example.administrator.szb.util.Toasts;
import com.example.administrator.szb.xzyw.SuccessActivity;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by D N on 2017/11/18.
 * 提交项目资料
 */

public class SQXMActivity extends BaseActivity {

    YWBDNEWBean ywbdBean;
    @Bind(R.id.sqxm_recyclerview)
    RecyclerView sqxmRecyclerview;
    @Bind(R.id.sqxm_text_bmxy)
    TextView sqxmTextBmxy;
    @Bind(R.id.sqxm_button_tj)
    Button sqxmButtonTj;
    @Bind(R.id.sqxm_bgzr_recyclerview)
    RecyclerView sqxmBgzrRecyclerview;
    @Bind(R.id.sqxm_text_info)
    TextView sqxmTextInfo;
    @Bind(R.id.sqxm_ll_bgzr_isShow)
    LinearLayout sqxmLlBgzrIsShow;
    @Bind(R.id.sqxm_ll_showinfo)
    LinearLayout sqxmLlShowinfo;
    private int counselor_id = 0;
    BaseAdapter<YWBDNEWBean.DataBean.ListBean> adapter;


    private TimePickerView pvCustomTime;//时间选择器

    HashMap<Integer, View> info_map = new HashMap<>();//输入类型的信息的集合
    HashMap<Integer, Integer> info_choose = new HashMap<>();//选择类型的信息的集合
    int who = 0;//记录被点击的位置；
    View view;//记录被点击的view
    ArrayList<YWBDNEWBean.DataBean.ListBean> mdata = new ArrayList<>();
    BaseAdapter<YWBDNEWBean.DataBean.ListBean> adapter_title;
    String sbzr_title = "";
    int sbzr_id  = 0;
    String yq = "其他要求";

    InputMethodManager imm;//软键盘
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sqxm_activity);
        ButterKnife.bind(this);
        SampleApplicationLike.getActivitiesInstance().add(this);
        initToolbar(R.id.sqxm_toolbar_include, "提交资料", new Callback() {
            @RequiresApi(api = Build.VERSION_CODES.KITKAT)
            @Override
            public void doSomeThing() {
                DialogUtil.showPopupwindow(SQXMActivity.this,R.layout.popuwindow_tcdl, ScreenExpressionUtils.dip2px(SQXMActivity.this, 324), ScreenExpressionUtils.dip2px(SQXMActivity.this, 164),R.layout.sqxm_activity, new CallbackPopuwindow() {
                    @Override
                    public void doSomeThing(View view) {
                        ((TextView) view.findViewById(R.id.textView14)).setText("修改资料");
                        ((TextView) view.findViewById(R.id.textView8)).setText("您的项目尚未提交，是否选择离开？");

                        ((TextView) view.findViewById(R.id.textView15)).setText("继续填写");
                        ((TextView) view.findViewById(R.id.textView9)).setText("离开");
                        ((TextView) view.findViewById(R.id.textView15)).setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                DialogUtil.popWindow.dissmiss();
                            }
                        });

                        ((TextView) view.findViewById(R.id.textView9)).setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                DialogUtil.popWindow.dissmiss();
                                XZYWActivity.ywbdBean = null;
                                XZGWYWActivity.ywbdBean = null;
                                finish();
                            }
                        });
                    }
                });
            }
        });
        imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);//软键盘实例

        if (XZYWActivity.ywbdBean != null){
            ywbdBean = XZYWActivity.ywbdBean;
            mdata.addAll(ywbdBean.getData().getList());
            initView();
            initRecyclerview();
        }else if(XZGWYWActivity.ywbdBean != null){
            ywbdBean = XZGWYWActivity.ywbdBean;
            mdata.addAll(ywbdBean.getData().getList());
            initView();
            initRecyclerview();
        }else{
            requestData();
        }


    }

    private void requestData() {
        HashMap<String, String> map = new HashMap<>();
        map.put("code", HttpUtil.getParam());
        map.put("business_id", getIntent().getIntExtra("id", -1) + "");
        map.put("counselor_id", counselor_id + "");
        String json = GetJsonDataUtil.simpleMapToJsonStr(map);
        String url = URLAddress.URLBASE + URLAddress.URL_BDYW;
        HttpUtil.RequestGsonPost(SampleApplicationLike.getQueueInstance(), Request.Method.POST, YWBDNEWBean.class, url, map, new Response.Listener() {
            @Override
            public void onResponse(Object response) {
                ywbdBean = (YWBDNEWBean) response;
                mdata.addAll(ywbdBean.getData().getList());
                if (ywbdBean.getResult() == 1) {
                    initView();
                    initRecyclerview();
                } else {
                    Toasts.show(SQXMActivity.this, "" + ywbdBean.getErr_msg(), Toast.LENGTH_SHORT);
                }


            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
    }

    private void initView() {
        sqxmTextInfo.setText(ywbdBean.getData().getWarnbus());
        if (getIntent().getIntExtra("genre", -1) == 1) {
            sqxmLlBgzrIsShow.setVisibility(View.VISIBLE);
            sbzr_id = ywbdBean.getData().getList().get(0).getId();
            sbzr_title =  ywbdBean.getData().getList().get(0).getTitle();
            initRecyclerviewTitle();
            sqxmLlShowinfo.setVisibility(View.GONE);
        }
    }

    private void initRecyclerviewTitle() {


        sqxmBgzrRecyclerview.setLayoutManager(new GridLayoutManager(this,mdata.size()));
        adapter_title = new BaseAdapter<YWBDNEWBean.DataBean.ListBean>(SQXMActivity.this, mdata) {
            @Override
            public void convert(final int position, BaseViewHolder holder, final YWBDNEWBean.DataBean.ListBean listBean) {
                ((TextView) holder.getView(R.id.sqxm_bgzr_title)).setText(listBean.getTitle());
                if (listBean.getChoose() == 0){
                    ((CheckBox)holder.getView(R.id.sqxm_bgzr_title)).setChecked(false);
                }else if (listBean.getChoose() == 1){
                    ((CheckBox)holder.getView(R.id.sqxm_bgzr_title)).setChecked(true);
                }

                if (position == 0 && listBean.getOnly_one() == 0){
                    mdata.get(position).setOnly_one(1);
                    ((CheckBox)holder.getView(R.id.sqxm_bgzr_title)).setChecked(true);
                    ((EditText)info_map.get(-3)).setHint(listBean.getDescbus());//
                    adapter.notifyDataSetChanged();
                }

                ((CheckBox)holder.getView(R.id.sqxm_bgzr_title)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                        if (b){
                            for (int i = 0; i < mdata.size(); i++) {
                                mdata.get(i).setChoose(0);
                            }
                            mdata.get(position).setChoose(1);
                            adapter_title.notifyDataSetChanged();
                            ((EditText)info_map.get(-3)).setHint(listBean.getDescbus());//
                            sbzr_id = listBean.getId();
                            sbzr_title = listBean.getTitle();
                        }
                    }
                });
            }

            @Override
            public int getLayoutId(int viewType) {
                return R.layout.view_sqxm_item_bgzr;
            }
        };
        sqxmBgzrRecyclerview.setAdapter(adapter_title);
        ywbdBean.getData().getList().clear();
    }

    private void addData() {
        YWBDNEWBean.DataBean.ListBean lxr = new YWBDNEWBean.DataBean.ListBean();
        lxr.setId(-1);
        lxr.setType(1);
        lxr.setTitle("联系人");
        lxr.setUnit(0);

        YWBDNEWBean.DataBean.ListBean lxfs = new YWBDNEWBean.DataBean.ListBean();
        lxfs.setId(-2);
        lxfs.setType(1);
        lxfs.setTitle("联系方式");

        if (SampleApplicationLike.getUserloginInstance().getId() != 0){
            String tel = SPUtils.getDatasString(SPUtils.USER_PHONE);
            lxfs.setTel_number(tel);
        }

        lxfs.setUnit(1);

        YWBDNEWBean.DataBean.ListBean qtyq = new YWBDNEWBean.DataBean.ListBean();
        qtyq.setType(-1);
        qtyq.setId(-3);

        if (getIntent().getIntExtra("genre",-1) == 1){
            qtyq.setTitle("需求说明");
        }else{
            qtyq.setTitle(""+yq);
        }


        ywbdBean.getData().getList().add(lxr);
        ywbdBean.getData().getList().add(lxfs);
        ywbdBean.getData().getList().add(qtyq);
    }

    private void initRecyclerview() {
        sqxmRecyclerview.setLayoutManager(new LinearLayoutManager(this));

        addData();

        adapter = new BaseAdapter<YWBDNEWBean.DataBean.ListBean>(this, ywbdBean.getData().getList()) {
            @Override
            public void convert(int position, BaseViewHolder holder, YWBDNEWBean.DataBean.ListBean listBean) {
                if (listBean.getType() == 1) {
                    ((TextView) holder.getView(R.id.tjzl_text_gpdm_sqxm)).setText(listBean.getTitle());

                    if (TextUtils.isEmpty(listBean.getUnit_text())) {
                        ((TextView) holder.getView(R.id.tjzl_text_dw_sqxm)).setVisibility(View.GONE);
                    } else {
                        ((TextView) holder.getView(R.id.tjzl_text_dw_sqxm)).setText(listBean.getUnit_text());
                    }

                    ((EditText) holder.getView(R.id.tjzl_edit_gpdm_sqxm)).setHint("请输入" + listBean.getTitle());
                    ((EditText) holder.getView(R.id.tjzl_edit_gpdm_sqxm)).setFilters(new InputFilter[]{new InputFilter.LengthFilter(18)});
                    if (!TextUtils.isEmpty(listBean.getTel_number())){
                        ((EditText) holder.getView(R.id.tjzl_edit_gpdm_sqxm)).setText(listBean.getTel_number());
                        ((EditText) holder.getView(R.id.tjzl_edit_gpdm_sqxm)).setFilters(new InputFilter[]{new InputFilter.LengthFilter(11)});
                    }
                    if (listBean.getUnit() == 1 || listBean.getUnit() == 2) {
                        ((EditText) holder.getView(R.id.tjzl_edit_gpdm_sqxm)).setInputType(InputType.TYPE_CLASS_NUMBER|InputType.TYPE_NUMBER_FLAG_DECIMAL);
                    } else if (listBean.getUnit() == 3) {//弹出时间框
                        ((EditText) holder.getView(R.id.tjzl_edit_gpdm_sqxm)).setHint("请选择" + listBean.getTitle());
                        (holder.getView(R.id.tjzl_iamge_dw_sqxm)).setVisibility(View.VISIBLE);
                        //((EditText)holder.getView(R.id.tjzl_edit_gpdm_sqxm)).setInputType(InputType.TYPE_CLASS_DATETIME);
                        ((EditText) holder.getView(R.id.tjzl_edit_gpdm_sqxm)).setKeyListener(null);
                        ((EditText) holder.getView(R.id.tjzl_edit_gpdm_sqxm)).setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                initCustomTimePicker((EditText) view.findViewById(R.id.tjzl_edit_gpdm_sqxm));//初始化时间选择器
                                pvCustomTime.show();
                            }
                        });
                    } else {
                        ((EditText) holder.getView(R.id.tjzl_edit_gpdm_sqxm)).setInputType(InputType.TYPE_CLASS_TEXT);
                    }

                    info_map.put(listBean.getId(), ((EditText) holder.getView(R.id.tjzl_edit_gpdm_sqxm)));//持有组件，方便将来取值

                } else if (listBean.getType() == 2) {
                    info_map.put(listBean.getId(), ((TextView) holder.getView(R.id.tjzl_text_gpsx_sqxm)));//持有组件，方便将来取值
                    ((TextView) holder.getView(R.id.tjzl_text_title_sqxm)).setText(listBean.getTitle());
                } else if (listBean.getType() == -1) {
                    info_map.put(listBean.getId(), ((EditText) holder.getView(R.id.tjzl_edit_yq_sqxm)));
                    ((TextView) holder.getView(R.id.tjzl_text_yq_sqxm)).setText(listBean.getTitle());
                    setEditEvent(((EditText)holder.getView(R.id.tjzl_edit_yq_sqxm)),R.id.tjzl_edit_yq_sqxm);
                    if (TextUtils.isEmpty(mdata.get(0).getDescbus())){
                        ((EditText)holder.getView(R.id.tjzl_edit_yq_sqxm)).setHint("请输入说明内容(最多200字)");
                    }else{
                        ((EditText)holder.getView(R.id.tjzl_edit_yq_sqxm)).setHint(mdata.get(0).getDescbus());
                    }

                }
            }

            @Override
            public int getLayoutId(int viewType) {

                /**
                 * todo 根据不同类型返回不同item
                 */

                if (ywbdBean.getData().getList().get(viewType).getType() == 1) {
                    return R.layout.view_sqyw_item_srx;
                } else if (ywbdBean.getData().getList().get(viewType).getType() == -1) {
                    //申请项目的其他要求
                    return R.layout.view_sqyw_item_qtyq;
                }
                return R.layout.view_sqyw_item_xzx;
            }
        };
        adapter.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
            @RequiresApi(api = Build.VERSION_CODES.KITKAT)
            @Override
            public void onItemClick(View view, int position) {
                if (ywbdBean.getData().getList().get(position).getUnit() == 3) {

                    if(imm.isActive()&&getCurrentFocus()!=null){
                        if (getCurrentFocus().getWindowToken()!=null) {
                            imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                        }
                    }

                    initCustomTimePicker((EditText) view.findViewById(R.id.tjzl_edit_gpdm_sqxm));//初始化时间选择器
                    pvCustomTime.show();
                } else if (ywbdBean.getData().getList().get(position).getType() == 2) {
                    if(imm.isActive()&&getCurrentFocus()!=null){
                        if (getCurrentFocus().getWindowToken()!=null) {
                            imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                        }
                    }
                    who = position;
                    BaseAdapter<YWBDNEWBean.DataBean.ListBean.BuschoicesBean> show_adapter = new BaseAdapter<YWBDNEWBean.DataBean.ListBean.BuschoicesBean>(SQXMActivity.this, ywbdBean.getData().getList().get(position).getBuschoices()) {
                        @Override
                        public void convert(int position, BaseViewHolder holder, YWBDNEWBean.DataBean.ListBean.BuschoicesBean buschoicesBean) {

                            //view = ((TextView)holder.getView(R.id.tjzl_text_gpsx_sqxm));
                            ((TextView) holder.getView(R.id.base_tjzl_popuwindow_text_item)).setText(buschoicesBean.getTitle());
                        }

                        @Override
                        public int getLayoutId(int viewType) {
                            return R.layout.view_popuwindow_base_tjzl_item;
                        }
                    };

                    show_adapter.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
                        @Override
                        public void onItemClick(View view, int position) {

                            ((TextView) info_map.get(ywbdBean.getData().getList().get(who).getId())).setText(ywbdBean.getData().getList().get(who).getBuschoices().get(position).getTitle());
                            info_choose.put(ywbdBean.getData().getList().get(who).getId(), ywbdBean.getData().getList().get(who).getBuschoices().get(position).getId());
                            popWindow.dissmiss();
                        }
                    });
                    showPopupwindow(R.layout.view_popuwindow_base_tjzl, R.layout.sqxm_activity, show_adapter);
                }
            }
        });

        sqxmRecyclerview.setAdapter(adapter);
    }

    private void initCustomTimePicker(final EditText tjzlTextFksj) {

        /**
         * @description
         *
         * 注意事项：
         * 1.自定义布局中，id为 optionspicker 或者 timepicker 的布局以及其子控件必须要有，否则会报空指针.
         * 具体可参考demo 里面的两个自定义layout布局。
         * 2.因为系统Calendar的月份是从0-11的,所以如果是调用Calendar的set方法来设置时间,月份的范围也要是从0-11
         * setRangDate方法控制起始终止时间(如果不设置范围，则使用默认时间1900-2100年，此段代码可注释)
         */
        Calendar selectedDate = Calendar.getInstance();//系统当前时间
        Calendar startDate = Calendar.getInstance();
        startDate.set(startDate.get(Calendar.YEAR), startDate.get(Calendar.MONTH), startDate.get(Calendar.DATE));
        Calendar endDate = Calendar.getInstance();
        endDate.set(startDate.get(Calendar.YEAR) + 5, 11, 31);
        //时间选择器 ，自定义布局
        pvCustomTime = new TimePickerView.Builder(this, new TimePickerView.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                tjzlTextFksj.setTextColor(getResources().getColor(R.color.toolbar_home));
                tjzlTextFksj.setText(getTime(date));
            }
        })
                /*.setType(TimePickerView.Type.ALL)//default is all
                .setCancelText("Cancel")
                .setSubmitText("Sure")
                .setContentSize(18)
                .setTitleSize(20)
                .setTitleText("Title")
                .setTitleColor(Color.BLACK)
               /*.setDividerColor(Color.WHITE)//设置分割线的颜色
                .setTextColorCenter(Color.LTGRAY)//设置选中项的颜色
                .setLineSpacingMultiplier(1.6f)//设置两横线之间的间隔倍数
                .setTitleBgColor(Color.DKGRAY)//标题背景颜色 Night mode
                .setBgColor(Color.BLACK)//滚轮背景颜色 Night mode
                .setSubmitColor(Color.WHITE)
                .setCancelColor(Color.WHITE)*/
               /*.gravity(Gravity.RIGHT)// default is center*/
                .setDate(selectedDate)
                .setRangDate(startDate, endDate)
                .setLayoutRes(R.layout.pickerview_custom_time, new CustomListener() {

                    @Override
                    public void customLayout(View v) {
                        final TextView tvSubmit = (TextView) v.findViewById(R.id.tv_finish);
                        TextView ivCancel = (TextView) v.findViewById(R.id.iv_cancel);
                        tvSubmit.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                pvCustomTime.returnData();
                                pvCustomTime.dismiss();
                            }
                        });
                        ivCancel.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                pvCustomTime.dismiss();
                            }
                        });
                    }
                })
                .setType(new boolean[]{true, true, true, false, false, false})
                .setLabel("年", "月", "日", "", "", "")
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setDividerColor(0xFF24AD9D)
                .build();

    }


    private String getTime(Date date) {//可根据需要自行截取数据显示
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        return format.format(date);
    }


    @OnClick({R.id.sqxm_button_tj, R.id.sqxm_text_bmxy})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.sqxm_button_tj:
                //com.example.administrator.szb.adapter.notifyDataSetChanged();
//                info_map.toString();
//                String a = info_map.get(ywbdBean.getData().getList().get(0).getId()).getText().toString();
                //String b = info_map.get(1).getText().toString();


                if (SampleApplicationLike.getUserloginInstance().getId() == 0) {
                    startActivity(new Intent(SQXMActivity.this, LoginNewActivity_two.class));
                } else {
                    doSubmit();
                }

                break;
            case R.id.sqxm_text_bmxy:
                Intent intent_web = new Intent(SQXMActivity.this,GZXYActivity.class);//额，
                intent_web.putExtra("title","保密承诺");
                intent_web.putExtra("id",2);
                startActivity(intent_web);
                break;
        }
    }

    private void doSubmit() {
        sqxmButtonTj.setEnabled(false);
        HashMap<String, String> map = new HashMap<>();
        map.put("code", HttpUtil.getParam());
        map.put("counselor_id", getIntent().getIntExtra("counselor_id",0)+"");
        map.put("users_id", "" + SampleApplicationLike.getUserloginInstance().getId());//测试
        map.put("namelink", (((EditText) info_map.get(ywbdBean.getData().getList().get(ywbdBean.getData().getList().size() - 3).getId())).getText().toString()));
        map.put("tel", (((EditText) info_map.get(ywbdBean.getData().getList().get(ywbdBean.getData().getList().size() - 2).getId())).getText().toString()));

        String content = (((EditText) info_map.get(ywbdBean.getData().getList().get(ywbdBean.getData().getList().size() - 1).getId())).getText().toString());

        if (TextUtils.isEmpty(content)){
            map.put("content",0+"");
        }else {
            map.put("content",content);
        }



        if (!TextUtils.isEmpty(sbzr_title)){
            map.put("business_id",""+sbzr_id);
        }else{
            map.put("business_id", getIntent().getIntExtra("id", -1) + "");
        }



        Iterator<Integer> iterator = info_map.keySet().iterator();

        while (iterator.hasNext()) {
            int key = iterator.next();
            View view = info_map.get(key);
            if (view instanceof EditText && key > 0) {
                map.put(key + "", ((EditText) view).getText().toString());
            }
        }




        Iterator<Integer> it = info_choose.keySet().iterator();
        while (it.hasNext()) {
            int key = it.next();
            map.put(key + "", info_choose.get(key) + "");
        }

        String json = GetJsonDataUtil.simpleMapToJsonStr(map);
        HttpUtil.RequestGsonPost(SampleApplicationLike.getQueueInstance(), Request.Method.POST, SQYWBean.class, URLAddress.URLBASE + URLAddress.URL_SUBMINT_BDYW, map, new Response.Listener() {
            @Override
            public void onResponse(Object response) {
                sqxmButtonTj.setEnabled(true);
                if (((SQYWBean) response).getResult() != 1) {
                    Toasts.show(SQXMActivity.this, "" + ((SQYWBean) response).getErr_msg(), Toast.LENGTH_SHORT);
                } else {
                    XZYWActivity.ywbdBean = null;
                    XZGWYWActivity.ywbdBean = null;
                    finish();
                    startActivity(new Intent(SQXMActivity.this, SuccessActivity.class));
                }

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                sqxmButtonTj.setEnabled(true);
                error.toString();
                DialogUtil.showToast(SQXMActivity.this,"加载失败");
                Log.e("pdf", "onErrorResponse: " + error.toString() );
            }
        });
    }


    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    @Override
    public void onBackPressed() {
        //super.onBackPressed();
        DialogUtil.showPopupwindow(SQXMActivity.this,R.layout.popuwindow_tcdl, ScreenExpressionUtils.dip2px(SQXMActivity.this, 324), ScreenExpressionUtils.dip2px(SQXMActivity.this, 164),R.layout.sqxm_activity, new CallbackPopuwindow() {
            @Override
            public void doSomeThing(View view) {
                ((TextView) view.findViewById(R.id.textView14)).setText("项目填写");
                ((TextView) view.findViewById(R.id.textView8)).setText("您的项目尚未提交，是否选择离开？");

                ((TextView) view.findViewById(R.id.textView15)).setText("继续填写");
                ((TextView) view.findViewById(R.id.textView9)).setText("离开");
                ((TextView) view.findViewById(R.id.textView15)).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        DialogUtil.popWindow.dissmiss();
                    }
                });

                ((TextView) view.findViewById(R.id.textView9)).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        DialogUtil.popWindow.dissmiss();
                        XZYWActivity.ywbdBean = null;
                        XZGWYWActivity.ywbdBean = null;
                        finish();
                    }
                });
            }
        });
    }
}
